home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / FIX < prev    next >
Encoding:
Text File  |  1985-12-28  |  2.1 KB  |  86 lines

  1. ;-------------------------fix routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 107
  4. ;
  5. ; NAME  FIX
  6. ;
  7. ; ROUTINE FOR Conversion from Internal Floating Point to 16-Bit Integer
  8. ;
  9. ; FUNCTION: This routine converts from internal single precision binary
  10. ; floating point to internal 16-bit signed two's complement integer.
  11. ;
  12. ; INPUT: Upon entry a single precision binary floating point is in
  13. ; SFPBUFF.  The single precision floating point nu ber has a 24-bit
  14. ; binary mantissa, a sign bit, and an 8-bit exponent biased by 128.
  15. ;
  16. ; OUTPUT: Upon exit a 16-bit signed two's complement binary number
  17. ; is in the DX register.
  18. ;
  19. ; REGISTERS USED:  Only DX is modified, used for output.
  20. ;
  21. ; SEGMENTS REFERENCED:  The data segment contains storage for SFPBUFF.
  22. ;
  23. ; ROUTINES CALLED:  None
  24. ;
  25. ; SPECIAL NOTES: Equates used to shorten address fields.
  26. ;
  27. ; ROUTINE TO CONVERT FROM INTERNAL FLOATING POINT TO INTERNAL INTEGER
  28. ; (truncate).
  29. ;
  30. fix    proc    far
  31. ;
  32. ; the number is in sfpbuff
  33. ;
  34.     push    cx        ; save registers
  35.     push    ax
  36. ;
  37. ; get the mantissa
  38.     mov    ax,sfpbuffw0    ; AX gets the low part
  39.     mov    dx,sfpbuffw2    ; DX gets high part
  40.     and    dx,007Fh    ; just the mantissa
  41.     or    dx,0080h    ; restore MSB
  42. ;
  43. ; get the exponent
  44.     mov    cl,sfpbuffb3    ; get the exponent
  45.     mov    ch,0        ; extend to 16-bit
  46.     sub    cx,88h        ; subtract bias
  47.     cmp    cx,0        ; check its sign
  48.     jl    fix1        ; if negative
  49.     jg    fix2        ; if positive
  50.     je    fix3        ; if zero
  51. ;
  52. fix1:
  53. ; shift right
  54.     neg    cx        ; absolute value
  55. ;
  56. fix2:
  57.     sar    dx,1        ; shift all bits right
  58.     rcr    ax,1        ; carry on
  59.     loop    fix2
  60. ;
  61.     jmp    fix4        ; end of case
  62. ;
  63. fix3:
  64. ; shift left
  65.     sal    ax,1        ; shift all bits left
  66.     rcl    dx,1        ; carry on
  67.     loop    fix3
  68. ;
  69.     jmp    fix4        ; end of case
  70. ;
  71. fix4:
  72. ; check the sign
  73.     mov    al,sfpbuffb2    ; get sign
  74.     and    al,80h        ; just bit 7
  75.     jz    fix5        ; is it on ?
  76.     neg    dx        ; two's compl if negative
  77. ;
  78. fix5:
  79. ;
  80.     pop    ax        ; restore registers
  81.     pop    cx
  82.     ret            ; return
  83. ;
  84. fix    endp
  85. ;-------------------------fix routine ends---------------------------+
  86.